package com.newtouch.bxzs.database.synchronize.batch.step;

import com.newtouch.bxzs.common.base.model.*;
import com.newtouch.bxzs.database.synchronize.batch.process.ProcesorLocalData;
import com.newtouch.bxzs.database.synchronize.batch.reader.ReaderLocalData;
import com.newtouch.bxzs.database.synchronize.batch.writer.WriteLocalData;
import com.newtouch.bxzs.database.synchronize.model.AdvertisementBO;
import org.springframework.batch.core.Step;
import org.springframework.batch.core.configuration.annotation.StepBuilderFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 本地数据批处理step
 * <p>
 * <b>History:</b>
 * <table border="1">
 * <tr>
 * <th>Date</th>
 * <th>Operator</th>
 * <th>Memo</th>
 * </tr>
 * <tr>
 * <td>2021/3/2 16:36</td>
 * <td>yuanjie</td>
 * <td>Create</td>
 * </tr>
 * </table>
 *
 * @author yuanjie
 * @version 1.0.0
 * @since 1.0.0
 */
@Component
public class LocalDataStep {

    @Autowired
    private StepBuilderFactory stepBuilderFactory;

    @Autowired
    private ReaderLocalData readerLocalData;

    @Autowired
    private ProcesorLocalData procesorLocalData;

    @Autowired
    private WriteLocalData writeLocalData;

    /**
     * 广告撤销Step
     * @return Step
     */
    public Step revokeAdvertisement(){
        return stepBuilderFactory.get("revokeAdvertisement")
                .<AdvertisementBO, AdvertisementBO>chunk(10)
                .reader(readerLocalData.getRevokeAdvertisement())
                .processor(procesorLocalData.processorAdvertisement())
                .writer(writeLocalData.revokeAdvertisement())
                .build();
    }

    /**
     * 广告发布
     * @return Step
     */
    public Step publishAdvertisement(){
        return stepBuilderFactory.get("publishAdvertisement")
                .<AdvertisementBO, AdvertisementBO>chunk(10)
                .reader(readerLocalData.getPublishAdvertisement())
                .processor(procesorLocalData.processorAdvertisement())
                .writer(writeLocalData.publishAdvertisement())
                .build();
    }

    /**
     * 产品的发布与撤销
     * @return Step
     */
    public Step updateProductStatus(){
        return stepBuilderFactory.get("updateProductStatus")
                .<Product,Product>chunk(10)
                .reader(readerLocalData.getProductList())
                .processor(procesorLocalData.processorProduct())
                .writer(writeLocalData.updateProductStatus())
                .build();
    }

    /**
     * 通知的发布与撤销
     * @return Step
     */
    public Step updateNotificationStatus(){
        return stepBuilderFactory.get("updateNotificationStatus")
                .<Notification,Notification>chunk(10)
                .reader(readerLocalData.getNotificationList())
                .processor(procesorLocalData.processorNotification())
                .writer(writeLocalData.updateNotificationStatus())
                .build();
    }

    /**
     * 知识小灵通的发布与撤销
     * @return Step
     */
    public Step updateKnowledgeCardStatus(){
        return stepBuilderFactory.get("updateKnowledgeCardStatus")
                .<KnowledgeCard,KnowledgeCard>chunk(10)
                .reader(readerLocalData.getKnowledgeCardList())
                .processor(procesorLocalData.processorKnowledgeCard())
                .writer(writeLocalData.updateKnowledgeCardStatus())
                .build();
    }

    /**
     * 知识库的发布与撤销
     * @return Step
     */
    public Step updateKnowledgeBaseStatus(){
        return stepBuilderFactory.get("updateKnowledgeBaseStatus")
                .<KnowledgeBase,KnowledgeBase>chunk(10)
                .reader(readerLocalData.getKnowledgeBaseList())
                .processor(procesorLocalData.processorKnowledgeBase())
                .writer(writeLocalData.updateKnowledgeBaseStatus())
                .build();
    }

    /**
     * 提醒升级
     * @return Step
     */
    public Step remindToUpgrade(){
        return stepBuilderFactory.get("remindToUpgrade")
                .<User,User>chunk(10)
                .reader(readerLocalData.getRemindToUpgrade())
                .writer(writeLocalData.remindToUpgrade())
                .build();
    }

    /**
     * 结束营销活动
     * @return Step
     */
    public Step finishMarketingActivity(){
        return stepBuilderFactory.get("finishMarketingActivity")
                .<Activity,Activity>chunk(10)
                .reader(readerLocalData.getMarketingActivity())
                .writer(writeLocalData.finishMarketingActivity())
                .build();
    }

    /**
     * 结束营销会议
     * @return Step
     */
    public Step finishMarketingConference(){
        return stepBuilderFactory.get("finishMarketingConference")
                .<Conference,Conference>chunk(10)
                .reader(readerLocalData.getMarketingConference())
                .writer(writeLocalData.finishMarketingConference())
                .build();
    }

    /**
     * 课程的发布与撤销
     * @return Step
     */
    public Step updateCourseStatus(){
        return stepBuilderFactory.get("updateCourseCardStatus")
                .<Course,Course>chunk(10)
                .reader(readerLocalData.getCourseList())
                .processor(procesorLocalData.processorCourseStatus())
                .writer(writeLocalData.updateCourseStatus())
                .build();
    }
    /**
     * 考试的发布与撤销
     * @return Step
     */
    public Step updateExaminationStatus(){
        return stepBuilderFactory.get("updateExaminationStatus")
                .<Examination,Examination>chunk(10)
                .reader(readerLocalData.getExamination())
                .processor(procesorLocalData.processorExamintionStatus())
                .writer(writeLocalData.updateExaminationStatus())
                .build();
    }
}
